#!/bin/sh
sh_script=$1
dt=$2
dt2=$3

if [ ${dt} == "19990101" ]; then
        #dt=`date "+%Y%m%d"`
        dt=`date -d "-1 days" +%Y%m%d`
fi
if [ ${dt2} == "19990101" ]; then
        #dt2=`date "+%Y%m%d"`
        dt2=`date -d "-1 days" +%Y%m%d`
fi

echo "dt: [${dt}, ${dt2}]."
echo "start ${sh_script} ${dt}..."

while [ $dt -le ${dt2} ]
do
    echo "${sh_script} $dt"
    sh ${sh_script} $dt
    if (($? != 0))
    then
        echo ">>> [${sh_script} $dt] process failed."
        exit 1
    fi
    dt=`date -d "$dt +1 days" "+%Y%m%d"`
done

exit $?

